﻿using System.Windows;

namespace VXCompany.SilverlightLogging.MVVM.Models.SyncBehaviors
{
	/// <summary>
	/// Behavior that attempts a sync at app crash.
	/// </summary>
	public class AppCrashSync : SyncBehavior
	{
		/// <summary>
		/// Starts behavior
		/// </summary>
		protected override void StartImpl()
		{
			Application.Current.UnhandledException += CurrentDomain_UnhandledException;
		}

		/// <summary>
		/// Stops behavior
		/// </summary>
		protected override void StopImpl()
		{
			Application.Current.UnhandledException -= CurrentDomain_UnhandledException;
		}

		/// <summary>
		/// Eventhandler for unhandled exception event.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		void CurrentDomain_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
		{
			BeginSynchronize();
		}

	}
}
